import json
import time

import requests


class BizParam:
    def __int__(self):
        self.cmskey = None  # CMS 接口密钥
        self.cmsakey = None  # CMS 接口系统来源标识
        self.ownerid = None  # CMS 货主ID
        self.wmsownerid = None  # CMS 物流货主ID
        self.saleDeptId = None  # CMS销售部门内码
        self.LogicDepts = None  # CMS逻辑库内码
        self.cstCode = None  # CMS客户编码
        self.cstName = None  # CMS客户名称
        self.cstAddressNo = None  # CMS客户地址编码
        self.expressCode = None  # 快递公司编码
        self.isDev = None  # 是否是开发环境
        self.gotExpress = None  # 是否负责安排快递业务
        self.plantParam = None  # 三方平台参数集


class WeixinInterface:
    """
通用微信企业号接口写入接口
"""
    # 开发环境
    DEVELOP_Url = "http://172.168.73.39:20212/weiZhi/"
    # 生产环境
    PRODUCTION_URL = "http://172.168.73.39:20212/weiZhi/"

    def __int__(self):
        self.is_dev = True
        self.aKey = None
        self.indoorKey = None

    def post_weixinservice(self, strMethod, strContent1):
        """
        调用写入CMS数据服务方法
        :param paramlist:
        :param strMethod:
        :return:
        """
        t = time.time()

        # 毫秒级时间戳
        timestamp = str(int(round(t * 1000)))

        strContent = json.dumps(strContent1)

        # print("加密后的:" + sign)
        url = self.DEVELOP_Url if self.is_dev is None or self.is_dev is True else self.PRODUCTION_URL
        urlString = url + strMethod + "?aKey=" + self.akey + "&indoorKey=" + self.indoorKey + "&timeStamp=" + timestamp
        # print(urlString)
        postrespond = requests.post(urlString, data=strContent)
        # print(postrespond)
        if postrespond.status_code != 200:
            raise Exception("CmsOpenApi.post error status_code != 200")
        buidler = json.loads(postrespond.text)

        return buidler
